import { defineConfig, loadEnv } from 'vite'
import vue from '@vitejs/plugin-vue'
import Components from 'unplugin-vue-components/vite';
import { VantResolver } from 'unplugin-vue-components/resolvers';
import path from "path";

// https://vitejs.dev/config/
export default defineConfig(({ command, mode }) => {
  const env = loadEnv(mode, process.cwd(), '')
  return {
    plugins: [
      vue(),
      Components({
        resolvers: [VantResolver()],
      }),
    ],
    base:'./',
    //设置的别名 
    resolve: {
      // 如果报错__dirname找不到，需要安装node,
      // 执行npm i @types/node --save-dev
      alias: {
        '@': path.resolve(__dirname, "./src"),
        "@assets": path.resolve(__dirname, "./src/assets"),
        "@components": path.resolve(__dirname, "./src/components"),
        "@views": path.resolve(__dirname, "./src/views"),
        "@utils": path.resolve(__dirname, "./src/utils"),
        "@api": path.resolve(__dirname, "./src/api"),
      },
    },
    // 服务配置
    server: {
      host:'local.99fund.com.cn',
      port: 3002,
      proxy: {
        "/PROXY_API": {
          target: env.VITE_APP_BASE_OLD_HOST,
          changeOrigin: true,
          rewrite: (path) => path.replace(/^\/PROXY_API/, ""),
        }
      },
    },
    build: {
      outDir: '../dist'
    }
  }
})